package com.maomao.maomaochong_i.personalPackage;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.maomao.maomaochong_i.MainActivity;
import com.maomao.maomaochong_i.R;
import com.maomao.maomaochong_i.application.MyApplication;
import com.maomao.maomaochong_i.dataBean.MySharePreference;

/**
 * Created by maomao on 2017/5/17.
 */

public class Login extends AppCompatActivity implements View.OnClickListener{
    private Context lContext;
    // 两个编辑框
    private EditText phoneEdit, passEdit;
    // 两个值
    private String number,password;
    // 三个按钮
    private Button loginBut,forgerBut,registerBut;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.personal_login);
        MyApplication.getInstance().addActivity(this);
        lContext = getApplicationContext();
        bindView();

    }

    private void bindView(){
        phoneEdit = (EditText) findViewById(R.id.editText1);
        passEdit = (EditText) findViewById(R.id.editText2);
        loginBut = (Button) findViewById(R.id.button1);
        forgerBut = (Button) findViewById(R.id.button2);
        registerBut = (Button) findViewById(R.id.button3);

        loginBut.setOnClickListener(this);
        forgerBut.setOnClickListener(this);
        registerBut.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch(v.getId()){
            // 登录按钮
            case R.id.button1:
                //先获得编辑框输入的值
                number = phoneEdit.getText().toString();
                password = passEdit.getText().toString();

                //判断是否正确


                //如果正确
                MySharePreference msp = new MySharePreference(lContext);
                //保存登录状态
                msp.setData("state",true);
                intent = new Intent(Login.this, MainActivity.class);
                intent.putExtra("boolean",true);
                startActivity(intent);
                break;

            // 忘记密码按钮
            case R.id.button2:
                intent = new Intent(Login.this, ForgetPassword.class);
                startActivity(intent);
                break;

            // 注册按钮
            case R.id.button3:
                intent = new Intent(Login.this, Register.class);
                startActivity(intent);
                break;
        }
    }
    //按手机返回键
    public boolean onKeyDown(int keyCode, KeyEvent event){
        if (keyCode == KeyEvent.KEYCODE_BACK){
            moveTaskToBack(false);
            MyApplication.getInstance().finish();
            return true;
        }
        return super.onKeyDown(keyCode,event);
    }
}


